package com.xm.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.xm.entity.Comdetail;
import com.xm.entity.News;
import com.xm.entity.Product;
import com.xm.uti.DBManager;
import com.xm.uti.QueryDataResult;

/**
 * 首页方法
 * 
 * @author 吴雪曼
 *
 */
public class HomeDaoImpl {


	/**
	 * 根据产品自身id编号查询信息，单击产品查询详情方法
	 * 
	 * @param id
	 * @return
	 */
	public ArrayList<Product> getChaDange(int id) {
		String sql = "select * from product where id= " + id;
		System.out.println("执行的sql语句是" + sql);
		QueryDataResult execQuery = DBManager.executeQuery(sql);
		ArrayList<Product> list = new ArrayList<Product>();
		if (execQuery != null) {
			ResultSet rs = execQuery.rs;
			try {
				while (rs.next()) {
					Product e = new Product();
					e.setId(rs.getInt(1));
					e.setProname(rs.getString("Proname"));
					e.setProtype(rs.getInt("Protype"));
					e.setColor(rs.getString("color"));
					e.setMarket(rs.getDouble("market"));
					e.setPrice(rs.getDouble("Price"));
					e.setBrand(rs.getString("Brand"));
					e.setStyle(rs.getString("Style"));
					e.setMaterial(rs.getString("Material"));
					e.setZuZhuang(rs.getString("Zuzhuang"));
					e.setDingzhi(rs.getString("Dingzhi"));
					e.setPicurl(rs.getString("Picurl"));
					e.setIsShow(rs.getString("isShow"));
					e.setModel(rs.getString("model"));
					e.setElement(rs.getString("element"));
					e.setPositioning(rs.getString("positioning"));
					list.add(e);
				}
			} catch (SQLException e) {
				// TODO: handle exception
				e.printStackTrace();
			} finally {
				execQuery.close();
			}
		}
		System.out.println(list);
		return list;
	}

	/**
	 * 单击产品系列图片跳转查询相应系列产品
	 * 
	 * @param Protype
	 * @return
	 */
	public ArrayList<Product> getSeriesUrl(int Protype) {
		String sql = "select * from product where Protype= " + Protype + " order by id desc";
		System.out.println("执行的sql语句是" + sql);
		QueryDataResult execQuery = DBManager.executeQuery(sql);
		ArrayList<Product> list = new ArrayList<Product>();
		if (execQuery != null) {
			ResultSet rs = execQuery.rs;
			try {
				while (rs.next()) {
					Product e = new Product();
					e.setId(rs.getInt(1));
					e.setProname(rs.getString("Proname"));
					e.setProtype(rs.getInt("Protype"));
					e.setPicurl(rs.getString("Picurl"));
					e.setIsShow(rs.getString("isShow"));
					list.add(e);
				}
			} catch (SQLException e) {
				// TODO: handle exception
				e.printStackTrace();
			} finally {
				execQuery.close();
			}
		}
		System.out.println(list);
		return list;
	}
	
	

}
